// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <melon/benchmark.h>
#include <melon/init/init.h>

#include <turbo/flags/flag.h>

#include <pollux/exec/tree_of_losers.h>
#include <tests/exec/utils/MergeTestBase.h>

using namespace kumo::pollux;
using namespace kumo::pollux::exec::test;

TestData narrow;
TestData medium;
TestData wide;

BENCHMARK(narrowTree) {
  MergeTestBase::test<TreeOfLosers<TestingStream>>(narrow, false);
}

BENCHMARK_RELATIVE(narrowArray) {
  MergeTestBase::test<MergeArray<TestingStream>>(narrow, false);
}

BENCHMARK(mediumTree) {
  MergeTestBase::test<TreeOfLosers<TestingStream>>(medium, false);
}

BENCHMARK_RELATIVE(mediumArray) {
  MergeTestBase::test<MergeArray<TestingStream>>(medium, false);
}

BENCHMARK(wideTree) {
  MergeTestBase::test<TreeOfLosers<TestingStream>>(wide, false);
}

BENCHMARK_RELATIVE(wideArray) {
  MergeTestBase::test<MergeArray<TestingStream>>(wide, false);
}

int main(int argc, char* argv[]) {
  melon::Init init{&argc, &argv};
  gflags::ParseCommandLineFlags(&argc, &argv, true);
  MergeTestBase test;
  test.seed(1);
  narrow = test.makeTestData(100'000'000, 7);
  medium = test.makeTestData(10'000'0000, 37);
  wide = test.makeTestData(10'000'0000, 1029);
  melon::runBenchmarks();
  return 0;
}
